package cj.web.activity.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import cj.web.activity.domain.PrizeGift;
import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;

/**
 * 
 * @author 
 *
 */
@DAO
public interface PrizeGiftDAO{
	@SQL("SELECT count(*) as num FROM PrizeGift where active_id=:1")
	int queryCount(String id);
	
	@SQL("select * from (select t.id,active_id,name,count,probability,t.remark,order_no,a.ActiveName "
			+"from (select row_number() over (order by id) as row_num,* from "
			+"PrizeGift where active_id=:1) t "
			+"join ActiveManagementList as a on t.active_id=a.ID "
			+"where row_num between :2 and :3) as h")
    List<Map> queryAll(String id,int start,int length);
	
	@SQL("select * from (select t.id,active_id,name,count,probability,t.remark,order_no,a.ActiveName "
			+"from (select row_number() over (order by id) as row_num,* from "
			+"PrizeGift) t "
			+"join ActiveManagementList as a on t.active_id=a.ID "
			+"where row_num between :1 and :2) as h")
    List<Map> queryAll(int start,int length);
	
	@SQL("SELECT count(*) as num FROM PrizeGift")
	int queryCount();
	
	@SQL("select distinct ID,ActiveName from ActiveManagementList")
	List<Map> selectItems();
    
    @SQL("select * from PrizeGift where id=:id")
    PrizeGift queryById(String id);
    
    @SQL("INSERT INTO PrizeGift ("
    		        		+ "id,"
			        		+ "active_id,"
			        		+ "name,"
			        		+ "count,"
			        		+ "probability,"
							+") VALUES ("
							+ ":t.id,"
							+ ":t.activeId,"
							+ ":t.name,"
							+ ":t.count,"
							+ ":t.probability,"
					+")")
    void create(@SQLParam("t") PrizeGift PrizeGift);
	
	@SQL("UPDATE PrizeGift SET "
		    		    						    		+ "active_id=:t.activeId,"
		        					    			        + "name=:t.name,"
		        					    			        + "count=:t.count,"
		        					    			        + "probability=:t.probability,"
		        						+ " WHERE id=:t.id")
    void update(@SQLParam("t") PrizeGift PrizeGift);
    
    @SQL("update PrizeGift set count = count -1 where active_id=:1 and name=:2 ")
    void deleteById(String id);
    
    @SQL("select * from PrizeGift where active_id=:1 order by order_no ")
    List<PrizeGift> queryByActiveId(int activeId);
    
    @SQL("update PrizeGift set count = count -1 where active_id=:1 and name=:2 ")
	void updateCountByActiveId(int activeId,String name);
}